<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>按规律插入数组</title>
</head>
<body>
    <input type="text">
    <button>插入</button>
    <p></p>
</body>
<script>
    let tex = document.querySelector('input');
    let btn = document.querySelector('button');
    let p = document.querySelector('p');

    let arr = [2, 5, 7, 10, 20];
    p.innerHTML = arr;

    btn.addEventListener('click', () => {
        arr.push(tex.value);
        arr.sort(function (n1, n2) {
            return n1 - n2;
        })
        p.innerHTML = arr;
        tex.value = '';
    })

</script>
</html>